package com.echo.code.thread;


import com.echo.code.thread.pool.ThreadPool;
import com.echo.code.thread.pool.impl.DefaultThreadPool;
import java.util.concurrent.TimeUnit;
import org.junit.Test;

/**
 * TestCase
 */
public class PoolTestCase {

  @Test
  public static void poolTestCase() throws InterruptedException {
    final ThreadPool pool = new DefaultThreadPool(10, 30, 20);
    for (int i = 0; i < 100; i++) {
      pool.execute(() -> {
        try {
          TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + " done.");
      });
    }
    TimeUnit.MINUTES.sleep(1);
    pool.shutdown();
  }

  /**
   * Junit在多线程支持上不太友好，建议直接在main方法单元测试
   * */
  public static void main(String[] args) {
    try {
      poolTestCase();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
